package com.htj.admin.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.htj.admin.dao.FrontUserDao;
import com.htj.admin.domain.FrontUser;
import com.htj.admin.service.FrontUserServiceInf;
import com.htj.util.DateTimeUtil;
import com.htj.vo.PageListVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class FrontUserServiceImpl implements FrontUserServiceInf {
    @Autowired
    FrontUserDao frontUserDao;

    /**
     * 登录
     * @param loginAct
     * @param loginPwd
     * @return
     */
    @Override
    public FrontUser login(String loginAct, String loginPwd) {
        FrontUser frontUser = frontUserDao.login(loginAct,loginPwd);
        return frontUser;
    }

    /**
     * 绑定邮箱
     *
     * @param id
     * @param email
     * @return
     */
    @Override
    public boolean bindEmail(String id, String email) {
        boolean bool = false;
        int flag = frontUserDao.bindEmail(id,email);
        if(flag == 1){
            bool = true;
        }
        return bool;
    }

    @Override
    public boolean add(FrontUser frontUser) {
        boolean bool = false;
        String time = DateTimeUtil.getSysTime();
        frontUser.setCreateTime(time);
        int flag = frontUserDao.add(frontUser);
        if(flag == 1){
            bool = true;
        }
        return bool;
    }

    @Override
    public PageListVo<FrontUser> pageList(Map<String, String> map) {
        PageListVo<FrontUser> pageListVo = new PageListVo<>();
        String currentPage = map.get("currentPage");
        String pageSize = map.get("pageSize");
        PageHelper.startPage(Integer.valueOf(currentPage),Integer.valueOf(pageSize));
        List<FrontUser> list = frontUserDao.pageList(map);
        PageInfo<FrontUser> pageInfo = new PageInfo<>(list);
        List<FrontUser> pageInfoList = pageInfo.getList();
        int total = (int) pageInfo.getTotal();
        pageListVo.setList(pageInfoList);
        pageListVo.setTotal(total);
        return pageListVo;
    }

    @Override
    public boolean update(FrontUser frontUser) {
        boolean bool = false;
        int flag = frontUserDao.update(frontUser);
        if(flag == 1){
            bool = true;
        }
        return bool;
    }

    @Override
    public boolean delete(Integer id) {
        boolean bool = false;
        int flag = frontUserDao.delete(id);
        if(flag == 1){
            bool = true;
        }
        return bool;
    }

    @Override
    public boolean changeStatus(Map<String, Integer> map) {
        boolean bool = false;
        int flag = frontUserDao.changeStatus(map);
        if(flag == 1){
            bool = true;
        }
        return bool;
    }

    @Override
    public FrontUser getUserById(String id) {
        FrontUser frontUser = frontUserDao.getUserById(id);
        return frontUser;
    }

    @Override
    public boolean changeVip(String vipId, String userId) {
        boolean bool = false;
        int flag = frontUserDao.changeVip(vipId,userId);
        if(flag == 1){
            bool = true;
        }
        return bool;
    }

}
